import koaRouter from "koa-router";
import { admin } from "../controller";
import path from "path";
import cgt from "../controller/chatgptController";
const router = new koaRouter({ prefix: "/admin" });
router.get("/", admin.index);
router.post("/upload", admin.upload);
router.post("/login", admin.login);
router.post("/register", admin.register);
router.get("/getNewsData", admin.getNewsData.bind(admin));
router.post("/chatgpt", cgt.chatgpt);
router.get("/downloadapp", async (ctx) => {
  const send = require("koa-send");
  let file_name = "zrtt.apk";
  let dir = path.resolve(__dirname, "../public");
  ctx.attachment(file_name);
  try {
    await send(ctx, file_name, { root: dir });
  } catch (error) {
    console.log("====================================");
    console.log(error);
    console.log("====================================");
  }
});
router.get("/downloadappb", async (ctx) => {
  const send = require("koa-send");
  let file_name = "论文小助手.apk";
  let dir = path.resolve(__dirname, "../public");
  ctx.attachment(file_name);
  try {
    await send(ctx, file_name, { root: dir });
  } catch (error) {
    console.log("====================================");
    console.log(error);
    console.log("====================================");
  }
});
router.get("/downloadappc", async (ctx) => {
  const send = require("koa-send");
  let file_name = "墨墨背单词.apk";
  let dir = path.resolve(__dirname, "../public");
  ctx.attachment(file_name);
  try {
    await send(ctx, file_name, { root: dir });
  } catch (error) {
    console.log("====================================");
    console.log(error);
    console.log("====================================");
  }
});
export { router };
